<template>
	<view class="page">
		<CustomNav :isBack="true" color="#fff" :topBgColor="topBgColor" title="缴费记录"></CustomNav>
		<image src="https://jinta-gas-charge-1306862033.cos.ap-chengdu.myqcloud.com/uniapp/home/banner.png"
			class="bg-img" mode="widthFix"></image>
		<view class="info-block">
			<view class="price-item">
				<view class="price"><text style="font-size: 26rpx;">￥</text>{{info.sumMoney}}元</view>
				<view class="text">缴费总金额</view>
			</view>
			<view class="line"></view>
			<view class="price-item">
				<view class="price"><text style="font-size: 26rpx;"></text>{{info.gas_meter_total}}m³</view>
				<view class="text">使用燃气总量</view>
			</view>
		</view>
		<view class="record-block">
			<view class="title FZHZGBJ">缴费记录</view>
			<template v-if="list.length>0">
				<view class="record-list" v-for="item in list" :key="item.id">
					<view class="name-item">
						<view class="name">燃气费</view>
						<view class="count">+{{item.payMoney}}</view>
					</view>
					<view class="time">{{item.createTime}}</view>
				</view>
			</template>
			<view v-if="more==false&&list.length==0" class="empty">暂无数据</view>
			<view v-else-if="more==false&&list.length>0" class="empty">没有更多了</view>
		</view>
	</view>
</template>

<script>
	import {
		isMore
	} from '@/util/util.js'
	import {
		getRecordsByUserId,
		getGasTotalInfoApi
	} from '@/api/payment.js'
	export default {
		components: {},
		data() {
			return {
				topBgColor: 'rgba(0,0,0,0)',
				info: {
					sumMoney: 0,
					gas_meter_total: 0
				},
				conf: {
					page: 1,
					limit: 10,
					name: ''
				},
				more: true,
				list: []
			}
		},
		methods: {
			getDetail() {
				return getGasTotalInfoApi().then((res) => {
					this.info = res
				});
			},
			handleRefresh() {
				this.conf.page = 1;
				this.more = true
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList(true)
			},
			getList(refresh = false) {
				return getRecordsByUserId({
					page: this.conf.page,
					limit: this.conf.limit
				}).then((res) => {
					let list = res.list || [];
					if (refresh) {
						this.list = list;
					} else {
						this.list = [...this.list, ...list]
					}
					this.more = isMore(this.conf.page, this.conf.limit, res.count)
				})
			}
		},
		onReachBottom() {
			if (this.more) {
				this.conf.page++;
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList();
			}
		},
		onLoad(e) {
			uni.showCustomLoading()
			Promise.all([this.getList(true), this.getDetail()]).finally(() => {
				uni.hideCustomLoading()
			})
		}
	}
</script>

<style lang="scss">
	.page {
		overflow: hidden;
		min-height: 100vh;
		background-color: #F4F8FF;

		.bg-img {
			width: 100%;
			height: 100%;
		}

		.info-block {
			width: calc(100% - 60rpx);
			margin: 30rpx auto;
			background: #FFFFFF;
			margin-top: -90rpx;
			border-radius: 20rpx;
			padding: 60rpx 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-around;

			.price-item {
				display: flex;
				flex-direction: column;
				align-items: center;

				.price {
					color: #0256FF;
					margin-bottom: 18rpx;
					font-size: 36rpx;
					font-weight: bold;
				}

				.text {
					font-size: 26rpx;
				}
			}

			.line {
				height: 80rpx;
				width: 1px;
				background: linear-gradient(to bottom, #FFFFFF, #0256FF, #FFFFFF);
			}
		}

		.record-block {
			width: calc(100% - 60rpx);
			margin: 30rpx auto;

			.title {
				font-size: 32rpx;
				margin-bottom: 30rpx;
			}

			.record-list {
				background-color: #FFFFFF;
				margin-bottom: 30rpx;
				padding: 30rpx;
				border-radius: 20rpx;

				.name-item {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 30rpx;
				}

				.time {
					margin-top: 30rpx;
					color: #767676;
					font-size: 28rpx;
				}
			}
		}
	}
</style>